import http from '@/utils/http';
import type { MutationTree, ActionTree, GetterTree } from 'vuex'
import type { State } from '../index'

interface Infos{
  [index: string]: unknown
}

export interface ChecksState{
  applyList: Infos[],
  checkList: Infos[]
}

const state: ChecksState = {
  applyList: [],
  checkList: []
}

const mutations: MutationTree<ChecksState> = {
  // Vuex不显示数据 组件可以成功拿到state数据
  updateApplyList(state, payload) {
    state.applyList = payload
  },
  // Vuex显示数据，组件无法获取state数据
  // updateApplyList(_state, payload) {
  //   state.applyList = payload
  // },
  updateCheckList(state, payload) {
    state.checkList = payload
  }
}
const actions: ActionTree<ChecksState, State> = {
  getApply(_context, payload) {
    return http.get('/checks/apply', payload)
  },
  postApply(_context, payload) {
    return http.post('/checks/apply', payload)
  },
  putApply(_context, payload) {
    return http.put('/checks/apply', payload)
  }
}
const getters: GetterTree<ChecksState, State> = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}